home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / c / 3d_dll.exe / DEMO.C < prev    next >
C/C++ Source or Header  |  1991-10-21  |  10KB  |  247 lines

  1. #include "windows.h"
  2. #include "demo.h"
  3. #include "ids.h"
  4. #include "three_d.h"
  5.  
  6.  
  7. HANDLE hInst;
  8. static HWND hMainWindow;
  9. static char szHeader[]="3-D Demo - By Ray Donahue";
  10.  
  11. extern BOOL FAR PASCAL DemoDlgProc(HWND,WORD,WORD,LONG);
  12. extern BOOL FAR PASCAL ComboDlgProc(HWND,WORD,WORD,LONG);
  13.  
  14. /****************************************************************************
  15.  
  16.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  17.  
  18.     PURPOSE: calls initialization function, processes message loop
  19.  
  20.     COMMENTS:
  21.  
  22.         Windows recognizes this function by name as the initial entry point 
  23.         for the program.  This function calls the application initialization 
  24.         routine, if no other instance of the program is running, and always 
  25.         calls the instance initialization routine.  It then executes a message 
  26.         retrieval and dispatch loop that is the top-level control structure 
  27.         for the remainder of execution.  The loop is terminated when a WM_QUIT 
  28.         message is received, at which time this function exits the application 
  29.         instance by returning the value passed by PostQuitMessage(). 
  30.  
  31.         If this function must abort before entering the message loop, it 
  32.         returns the conventional value NULL.  
  33.  
  34. ****************************************************************************/
  35.  
  36. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  37. HANDLE hInstance;            /* current instance         */
  38. HANDLE hPrevInstance;                      /* previous instance        */
  39. LPSTR lpCmdLine;             /* command line             */
  40. int nCmdShow;                /* show-window type (open/icon) */
  41. {
  42.     MSG msg;                 /* message                         */
  43.  
  44.     if (!hPrevInstance)                /* Other instances of app running? */
  45.    if (!InitApplication(hInstance)) /* Initialize shared things */
  46.        return (FALSE);          /* Exits if unable to initialize     */
  47.  
  48.     /* Perform initializations that apply to a specific instance */
  49.  
  50.     if (!InitInstance(hInstance, nCmdShow))
  51.         return (FALSE);
  52.  
  53.     /* Acquire and dispatch messages until a WM_QUIT message is received. */
  54.  
  55.     while (GetMessage(&msg,       /* message structure                        */
  56.        NULL,         /* handle of window receiving the message */
  57.        NULL,         /* lowest message to examine               */
  58.        NULL))        /* highest message to examine       */
  59.    {
  60.          TranslateMessage(&msg);        /* Translates virtual key codes      */
  61.          DispatchMessage(&msg);         /* Dispatches message to window      */
  62.     }
  63.     return (msg.wParam);          /* Returns the value from PostQuitMessage */
  64. }
  65.  
  66.  
  67. /****************************************************************************
  68.  
  69.     FUNCTION: InitApplication(HANDLE)
  70.  
  71.     PURPOSE: Initializes window data and registers window class
  72.  
  73.     COMMENTS:
  74.  
  75.         This function is called at initialization time only if no other 
  76.         instances of the application are running.  This function performs 
  77.         initialization tasks that can be done once for any number of running 
  78.         instances.  
  79.  
  80.         In this case, we initialize a window class by filling out a data 
  81.         structure of type WNDCLASS and calling the Windows RegisterClass() 
  82.         function.  Since all instances of this application use the same window 
  83.         class, we only need to do this when the first instance is initialized.  
  84.  
  85.  
  86. ****************************************************************************/
  87.  
  88. BOOL InitApplication(hInstance)
  89. HANDLE hInstance;              /* current instance       */
  90. {
  91.     WNDCLASS  wc;
  92.  
  93.     /* Fill in window class structure with parameters that describe the       */
  94.     /* main window.                                                           */
  95.  
  96.     wc.style = CS_HREDRAW|CS_VREDRAW;                    /* Class style(s).                    */
  97.     wc.lpfnWndProc = MainWndProc;       /* Function to retrieve messages for  */
  98.                                         /* windows of this class.             */
  99.     wc.cbClsExtra = 0;                  /* No per-class extra data.           */
  100.     wc.cbWndExtra = 0;                  /* No per-window extra data.          */
  101.     wc.hInstance = hInstance;           /* Application that owns the class.   */
  102.     wc.hIcon = LoadIcon(hInstance, "ddd");
  103.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  104.     wc.hbrBackground = GetStockObject(LTGRAY_BRUSH); 
  105.     wc.lpszMenuName =  "DemoMenu";   /* Name of menu resource in .RC file. */
  106.     wc.lpszClassName = "DemoWClass"; /* Name used in call to CreateWindow. */
  107.  
  108.     /* Register the window class and return success/failure code. */
  109.  
  110.    return(RegisterClass(&wc));
  111. }
  112.  
  113.  
  114. /****************************************************************************
  115.  
  116.     FUNCTION:  InitInstance(HANDLE, int)
  117.  
  118.     PURPOSE:  Saves instance handle and creates main window
  119.  
  120.     COMMENTS:
  121.  
  122.         This function is called at initialization time for every instance of 
  123.         this application.  This function performs initialization tasks that 
  124.         cannot be shared by multiple instances.  
  125.  
  126.         In this case, we save the instance handle in a static variable and 
  127.         create and display the main program window.  
  128.         
  129. ****************************************************************************/
  130.  
  131. BOOL InitInstance(hInstance, nCmdShow)
  132.     HANDLE          hInstance;          /* Current instance identifier.       */
  133.     int             nCmdShow;           /* Param for first ShowWindow() call. */
  134. {
  135.     HWND            hWnd;               /* Main window handle.                */
  136.  
  137.     /* Save the instance handle in static variable, which will be used in  */
  138.     /* many subsequence calls from this application to Windows.            */
  139.  
  140.     hInst = hInstance;
  141.  
  142.     /* Create a main window for this application instance.  */
  143.  
  144.     hWnd = CreateWindow(
  145.         "DemoWClass",                /* See RegisterClass() call.          */
  146.         "3-D Demonstration Program",   /* Text for window title bar.         */
  147.         WS_OVERLAPPEDWINDOW,            /* Window style.                      */
  148.         0,                  /* Default horizontal position.       */
  149.         0,                  /* Default vertical position.         */
  150.         GetSystemMetrics(SM_CXSCREEN),                  /* Default width.                     */
  151.         GetSystemMetrics(SM_CYSCREEN),                  /* Default height.                    */
  152.         NULL,                           /* Overlapped windows have no parent. */
  153.         NULL,                           /* Use the window class menu.         */
  154.         hInstance,                      /* This instance owns this window.    */
  155.         NULL                            /* Pointer not needed.                */
  156.     );
  157.  
  158.     /* If window could not be created, return "failure" */
  159.  
  160.     if (!hWnd)
  161.         return (FALSE);
  162.  
  163.    hMainWindow = hWnd;
  164.  
  165.     /* Make the window visible; update its client area; and return "success" */
  166.    ShowWindow(hMainWindow,nCmdShow);
  167.    UpdateWindow(hMainWindow);
  168.  
  169.     return (TRUE);               /* Returns the value from PostQuitMessage */
  170.  
  171. }
  172.  
  173. /****************************************************************************
  174.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  175. ****************************************************************************/
  176.  
  177. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  178. HWND hWnd;             /* window handle                  */
  179. unsigned message;         /* type of message             */
  180. WORD wParam;              /* additional information      */
  181. LONG lParam;              /* additional information      */
  182. {
  183.    static FARPROC lpprocDemoDlg;
  184.    static HFONT hFont;
  185.    PAINTSTRUCT ps;
  186.    RECT rc;
  187.  
  188.     switch (message) {
  189.  
  190.    case WM_CREATE:
  191.       hFont = CreateFont(40,5,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
  192.        CLIP_DEFAULT_PRECIS,PROOF_QUALITY,VARIABLE_PITCH|FF_SWISS,"Helv");
  193.       return(DefWindowProc(hWnd,message,wParam,lParam));
  194.  
  195.    case WM_DES